<?php

class Page extends Module
{

	function __construct ($db){
		$this->set_db($db);
	}

	function have_page($slug){

		$sql = "SELECT * FROM page WHERE slug = '$slug'";

		$rss = $this->db->query($sql);

		if($line = $this->db->fetchNextObject($rss)){
			return true;
		}

		return false;

	}

	function get_page($id){

		$sql = "SELECT * FROM page WHERE id = '$id'";

		$rss = $this->db->query($sql);

		if($line = $this->db->fetchNextObject($rss)){
			$result['page'] = $line->page;
			$result['detail']= $line->detail;
		}else{
			$result['page'] = "ผิดพลาด";
			$result['detail'] = "ไม่พบหน้าเพจ";
		}

		return $result;
	}

	function rain_display($slug, $tpl, $template){

		$sql = "SELECT * FROM page WHERE slug = '$slug'";

		$rss = $this->db->query($sql);

		if($line = $this->db->fetchNextObject($rss)){
			$result['page'] = $line->page;
			$result['detail']= $line->detail;
		}else{
			$result['page'] = "ผิดพลาด";
			$result['detail'] = "ไม่พบหน้าเพจ";
		}

		$tpl->assign("page", $result['page']);
		$tpl->assign("detail", $result['detail']);
		$tpl->draw($template);
	}

	function get_page_form_slug($slug){

		$sql = "SELECT * FROM page WHERE slug = '$slug'";

		$rss = $this->db->query($sql);

		if($line = $this->db->fetchNextObject($rss)){
			$result['page'] = $line->page;
			$result['detail']= $line->detail;
		}else{
			$result['page'] = "ผิดพลาด";
			$result['detail'] = "ไม่พบหน้าเพจ";
		}

		return $result;
	}
}

?>